package com.ymx.darling.session.defaults;

import com.ymx.darling.build.DarlingConfig;
import com.ymx.darling.build.Configuration;
import com.ymx.darling.build.ConfigurationBuilder;
import com.ymx.darling.session.Session;
import com.ymx.darling.session.SessionFactory;

/**
 * 默认的SessionFactory实现类
 * @author 爱Java的小于
 */
public class DefaultSessionFactory implements SessionFactory {
    /**
     * 全局配置实例
     */
    private final Configuration configuration;


    /**
     * 根据配置对象构建一个MapperFactory实例
     * @param config DarlingConfig
     */
    public DefaultSessionFactory(DarlingConfig config){
        this.configuration = new ConfigurationBuilder().builder(config);
    }


    @Override
    public Session openSession() {
        return this.openSession(false);
    }

    @Override
    public Session openSession(boolean isAutoCommit) {
        return new DefaultSession(configuration, isAutoCommit);
    }

    @Override
    public Configuration getConfiguration() {
        return this.configuration;
    }
}
